package com.haoran.dwz.common.redis;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import com.haoran.dwz.common.handler.PermissionCacheHandler;
import com.haoran.dwz.common.security.UsmFilterInvocationSecurityMetadataSourceService;

@Service
@Primary
public class PermissionMessageDelegateHandler extends AbstractMessageDelegateHandler {
	@Autowired
	private UsmFilterInvocationSecurityMetadataSourceService usmfismss;
 
	@Override
	public void handleMessage(Serializable message, String channel) {
		if (message != null) {
			if(message instanceof String) {
				String msg = (String)message;
				if(PermissionCacheHandler.SYNCHRONIZE_PERMISSION_CACHE_MESSAGE.equals(msg)) {
					try {
						usmfismss.synchronizeSecurityMetadataSourcetToCache();
						logger.info("同步系统权限缓存Success!");
					} catch (Exception e) {
						logger.error("同步系统权限缓存失败", e);
					}
				}
			}
		} else {
			handleMessageToSuccessor(message, channel);
		}
	}
}